import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './styles/index.scss'

// 引入自己的button插件
import MyButton from './components/button'

// 启用自己button插件
Vue.use(MyButton)
// 启用elementui
Vue.use(ElementUI)
// 设置部署不显示提示信息
Vue.config.productionTip = false

// 添加全局导航守卫
router.beforeEach((to, from, next) => {
  // to and from are Route Object,next() must be called to resolve the hook
  /**
   * 如果用户登录了，直接调用next()方法，不进行拦截，
   * 如果未登录，则直接跳转登录界面
   */
  let mytoken = localStorage.getItem('mytoken')
  if (mytoken) {
    next()
  } else {
    if (to.name !== 'login') {
      next('/login')
    } else {
      next()
    }
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
